/*
 * User: user
 * Date: 15/12/2007
 * Time: 22:59:17
 */
package org.conann.metadata.records;

import static com.google.common.base.Preconditions.checkNotNull;
import net.jcip.annotations.Immutable;
import org.conann.metadata.BeanMD;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.Set;

@Immutable
public class Record<T extends AnnotatedElement> {

    private final BeanMD beanMD;
    private final T element;

    public Record(final T element) {
        checkNotNull(element);
        this.element = element;
        beanMD = new BeanMD(element);
    }

    public boolean isAnnotatedBy(Class<? extends Annotation> annotationClass) {
        checkNotNull(annotationClass);
        for (Annotation annotation : getAllAnnotations()) {
            if (annotationClass.equals(annotation.annotationType())) {
                return true;
            }
        }
        return false;
    }

    public Set<Annotation> getAllAnnotations() {
        return beanMD.getAll();
    }

    public T getElement() {
        return element;
    }

    public BeanMD getComponentMD() {
        return beanMD;
    }
}